<template>
  <el-dialog title="编辑用户" :visible.sync="dialogVisible" width="30%" :before-close="close">
    <el-form ref="form" :rules="rules" :model="form" label-width="80px">
      <el-form-item prop="name" label="用户名">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item prop="role" label="用户角色">
        <el-select style="width:100%" v-model="form.role" placeholder="请选择用户角色">
          <el-option label="管理员" value="2" ></el-option>
          <el-option label="审核员" value="1" ></el-option>
          <el-option label="普通用户" value="0" ></el-option>
        </el-select>
      </el-form-item>
      <!--            <el-form-item prop="nickName" label="昵称">-->
      <!--                <el-input v-model="form.nickName"></el-input>-->
      <!--            </el-form-item>-->
      <!--       <el-form-item prop="password" label="密码">
        <el-input type="password" v-model="form.password"></el-input>
      </el-form-item>-->
      <!--      <el-form-item prop="status" label="禁用与否">
        <el-select style="width:100%" v-model="form.role" placeholder="请选择用户是否禁用">
          <el-option label="启用" value="1" ></el-option>
          <el-option label="禁用" value="0" ></el-option>
        </el-select>
      </el-form-item>
      -->

    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="submit">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script lang="ts">
import { Component, Prop, Vue } from "vue-property-decorator";
import { AddUser, EditUser } from "../../apis/apis";
import { number } from "echarts/core";
@Component({
  name: "EditPersonDialog"
})
export default class EditPersonDialog extends Vue {
  @Prop({ type: Boolean, default: false }) dialogVisible!: boolean;
  @Prop({ type: Number, default: 0 }) oldId!: number;
  form = {
    name: 'asd',
    role: '',
    status: '',
    // nickName: '',
    // password: '',
  };
  rules = {
    name: { required: true, message: "请输入用户名", trigger: "blur" },
    role: { required: true, message: "请选择用户角色", trigger: "change" }
    // nickName: { required: true, message: '请输入昵称', trigger: 'blur' },
    //password: { required: true, message: '请输入密码', trigger: 'blur' },
  };

  close(): void {
    this.dialogVisible = false;
    console.log("关闭成功");
  }

  //提交用户修改后的消息
  submit(): void {
    console.log(this.form.name);
    console.log(this.oldId);
    let b = Number(this.form.role)
    console.log(this.form.name);
    
    EditUser(this.form.name,b,this.oldId).then((res: any) => {
     console.log(res.data);
     if(res.data.code==='200')
      {
        this.$message({
          message: '添加成功',
          type: 'success'
        })
      }
      this.dialogVisible = false
    }).catch((err) =>{
      console.log(err);
   })

  }
  
}
</script>

<style lang="scss" scoped>
</style>